import glob
from os import path

class PythonObject:
    def __init__(self, name):
        self.name = name
        
    def hasObject(self, name):
        return hasObject(name)
    
    def getObject(self, name):
        if self.hasObject(name):
            return PythonObject(name)
        else:
            return None
    
    def hasVar(self, name):
        return hasVar(self.name,name)
    
    def setVar(self, name, val):
        setVar(self.name,name,val)
        
    def getVar(self, name):
        return getVar(self.name,name)
    
    def defaultVar(self, name, val):
        if not self.hasVar(name):
            self.setVar(name,val)
        return self.getVar(name)
    
    def runAction(self, type, name = None):
        return runAction(self.name, type, name or type)
    
    def stopAction(self, name):
        return stopAction(self.name, name)
    
    def stopAllActions(self):
        stopAllActions(self.name)
        
    def load(self, filename):
        load(self.name, filename)
        
    def deleteObject(self, name):
        deleteObject(name)
        
    def delete(self):
        self.deleteObject(self.name)
        
    def shutdown(self):
        shutdown()
        
    def makeObject(self, name):
        return PythonObject(makeObject(name))
    
    def log(self, *v):
        log(self.name, ' '.join(map(str,v)))
        
    def runScript(self, name):
        runScript(self.name, name)
        
    def publish(self, cmd, **args):
        publish(cmd,args)
        
    def getAllObjectNames(self):
        return getObjectNames()
        
    def getAllObjects(self):
        return dict([(name,PythonObject(name)) for name in getObjectNames()])
    
    def deferRpc(self, cmd, **args):
        requestRpc(self.name,cmd,args)
        def defer():
            return finishRpc(self.name,cmd)
        return defer
    
    def callRpc(self, cmd, **args):
        return self.deferRpc(cmd,**args)()
